// If we got a valid object here and also above, that
// is a failure condition anyway and we will return an
// empty string. So it doesn't matter if we overwrite
// the value here.
//
if (nodeType($kids[$i]) == "transform")
{
$validObj = canBeSoft( $kids[$i] );
if (size($validObj) > 0)
{
$successCount++;
$result = $validObj;
}
}
}
if ($successCount > 1)
{
$result = "";
}
}
return $result;
}
global proc dynCreateSoft( int $hide, int $history, int $goal, float $goalWeight, int $makeCopySoft )
//
// Description:
// Implement the "duplicate, make copy soft" and "duplicate, mnake original soft"
// options of the soft body menu.
// If $hide is 1, hide the original object;
// If $history is 1, duplicate the upstream graph ("duplicate -un")
// If $goal is 1, make the non-soft object a goal using weight $goalWeight.
{
// Get selected objects. Need to save them in case we wish to hide
// them or use them as goals.
//
string $selList[] = `ls -sl`;
string $objList[];
string $rigidNodes[] = `ls -type rigidBody`;
// Build the actual list we will work on.
// Screen out any objects whose parents
// are already in list, or which are already soft.
//
int $i;
int $objIndex = 0;
for ( $i = 0; $i < size( $selList ); $i++ )
{
string $obj = $selList[ $i ];
// Is this already a particle object?
//
if (`particleExists $selList[$i]`)
{
error( $obj + " is already a particle object or soft body. Please de-select it.");
}
else
//
// is this a rigid node or the parent of one?
//
if ((!$makeCopySoft) && ((objInList( $obj, $rigidNodes )) ||
(childInList( $obj, $rigidNodes ))))
{
error( $obj + " belongs to a rigid node. It cannot be converted into a soft body. Please select the original geometry shape and use the duplicate option. " );
}
else
{
// Get the actual valid geometry is there is one.
//
string $validObj = canBeSoft($obj);
if (0 == size($validObj))
{
error( $obj + ": This object cannot be made soft (it has no valid geometry, or too many). Please check your selection." );
}
else
//
// is the object in the list already?
//
if ( (!parentInList( $validObj, $objList )) &&
(!objInList( $validObj, $objList )) )
{
// Add to list.
//
$objList[ $objIndex ] = $validObj;
$objIndex++;
}
}
}
// do we have any valid objects to work on?
//
if (size($objList) == 0)
{
error( "no objects which could be made soft were selected. Please select a NURBS, polygonal, wire, or lattice object which isn't already a rigid or soft body.");
}
// At this point the pared-down list contains only
// objects which can be made soft, so we can proceed to work on them.
// Replace original selection list with pared-down list
// This is ok because what we are about to do will change the selection anyway.
//
string $dupObj[];
int $index = 0;
for ($index = 0; $index < size($objList); $index++)
{
// Duplicate the selected objects.
// dupObj stores the return from "duplicate."
// Note that this is always the transform of the duplicated object.
// Duplicate individually and store only the fifrst item in the result.
// This is necessary because when there is a curve on surface,
// the names of both the surface and the curve are returned from
// duplicate, and we do not want the latter.
//
string $result[];
select -r $objList[$index];
if ($history)
$result = `duplicate -un`;
else
$result = `duplicate`;
$dupObj[$index] = $result[0];
}
string $softObj[];
if ($makeCopySoft)
{
// make duplicate soft:
// Remove any duplicate rigid bodies just created.
// The duplicate operation duplicates all the children
// including the rigid body. We do not want the duplicate
// rigid body because then we cannot make it soft.
// Note that we can get in this situation only if the user
// selected the original geometry of the rigid body shape;
// that is a correct workflow and we want to allow it.
//
string $dupKids[] = `listRelatives -pa $dupObj`;
for ($i = 0; $i < size($dupKids); $i++)
{
if ("rigidBody" == `nodeType $dupKids[$i]`)
{
delete $dupKids[$i];
}
}
// Now parent copy to world, if it's not already
//
for ($i = 0; $i < size($dupObj); $i++)
{
string $theDupObj = $dupObj[$i];
if (size(`listRelatives -parent $theDupObj`) > 0)
parent -world $dupObj[$i];
}
// Rename the copy according to naming convention established.